home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / bm_cpio.gz / unixbm.cpio / pc.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  4KB  |  208 lines

  1. /* This file contains machine specific functions */
  2. #include <stdio.h>
  3.  
  4. /* This file is an attempt at keeping thing portble while taking
  5. * advantage of some of the faster io functions in the turbo lib.
  6. * It seems they all do it their own way but here it goes
  7. */
  8.  
  9. /* directory search utility for DOS */
  10. #if    defined(MICROSOFT)
  11. #include <sys/types.h>
  12. #endif
  13. #if    defined(MICROSOFT) || defined(AZTEC)
  14. #include <signal.h>
  15. #endif
  16. #if    defined(MICROSOFT) || defined(__TURBOC__)
  17. #include <sys/stat.h>
  18. #include <dos.h>
  19. #include <conio.h>
  20. #define ST_RDONLY    0x01    /* read only file */
  21. #define ST_HIDDEN    0x02    /* hidden file */
  22. #define ST_SYSTEM    0x04    /* system file */
  23. #define ST_VLABEL    0x08    /* volume label */
  24. #define ST_DIRECT    0x10    /* file is a sub-directory */
  25. #define ST_ARCHIV    0x20    /* set when file has been written and closed */
  26. #endif
  27. #ifdef AZTEC
  28. #include <stat.h>
  29. #endif
  30.  
  31. #define REGFILE    (ST_HIDDEN|ST_SYSTEM|ST_DIRECT)
  32. #define    SET_DTA        0x1a
  33. #define    FIND_FIRST    0x4e
  34. #define    FIND_NEXT    0x4f
  35.  
  36. struct dirent {
  37.     char rsvd[21];
  38.     char attr;
  39.     short ftime;
  40.     short fdate;
  41.     long fsize;
  42.     char fname[13];
  43. };
  44. /* wildcard filename lookup */
  45. filedir(name,times,ret_str)
  46. char *name;
  47. int times;
  48. char *ret_str;
  49. {
  50.     register char *cp,*cp1;
  51.     static struct dirent sbuf;
  52. #if    defined(MICROSOFT) || defined(__TURBOC__)
  53.     union REGS regs;
  54. #endif
  55.  
  56.     bdos(SET_DTA,(unsigned)&sbuf,0);    /* Set disk transfer address */
  57.  
  58. #if    defined(MICROSOFT) || defined(__TURBOC__)
  59.     regs.h.ah = (times == 0) ? FIND_FIRST : FIND_NEXT;
  60.     regs.x.dx = (unsigned int) name;
  61.     regs.x.cx = (unsigned int) REGFILE;
  62.     intdos(®s,®s);
  63.     if (regs.x.cflag) 
  64.         sbuf.fname[0] = '\0';
  65. #else
  66.     /* Find matching file */
  67.     if(dos(times == 0 ? FIND_FIRST:FIND_NEXT,0,REGFILE,name,0,0) == -1)
  68.         sbuf.fname[0] = '\0';
  69. #endif
  70.  
  71.     /* Copy result to output, forcing to lower case */
  72.     for(cp = ret_str,cp1 = sbuf.fname; cp1 < &sbuf.fname[13] && *cp1 != '\0';)
  73.         *cp++ = tolower(*cp1++);
  74.     *cp = '\0';
  75. }
  76.  
  77. /* This function should put the tty in a mode such that signgle characters
  78. * can be read without waiting for a complete line. Echo should be on.
  79. */
  80. setrawmode()
  81. {}
  82.  
  83. /* This function should restore the tty modes back to cooked mode */
  84. setcookedmode()
  85. {}
  86.  
  87. /* This function return one charater form the keyboard. It will wait
  88. * for a character to be input. This function will echo the character.
  89. * This funtion will return afer each character is typed if rawmode is set
  90. */
  91. int
  92. getrch()
  93. {
  94.     int    c;
  95. #if    defined(AZTEC) || defined(MICROSOFT) || defined(__TURBOC__)
  96.     c = bdos(1,0,0);
  97. #endif
  98.     return(c & 0xff);
  99. }
  100.  
  101. /* This function show clear screen and put cursor at top of screen */
  102. screen_clear()
  103. {
  104. #ifdef AZTEC
  105.     extern    int    scr_clear();
  106.     scr_clear();    /* from lib S */
  107. #endif
  108. #if    defined(MICROSOFT) || defined(__TURBOC__)
  109.     /* clear screen using window scroll up */
  110.     union REGS regs;
  111.     regs.h.ah = 6;
  112.     regs.h.al = 0;
  113.     regs.h.ch = 0;
  114.     regs.h.cl = 0;
  115.     regs.h.dh = 24;
  116.     regs.h.dl = 79;
  117.     regs.h.bh = 7;
  118.     int86(0x10,®s,®s);
  119.     /* home the cursor */
  120.     regs.h.ah = 2;
  121.     regs.h.bh = 0;
  122.     regs.h.dh = 0;
  123.     regs.h.dl = 0;
  124.     int86(0x10,®s,®s);
  125. #endif
  126. }
  127.  
  128. #ifdef AZTEC
  129. /* This is the aztec specific setvbuf since the Aztec lib doesnt have one */
  130. setvbuf(stream,buffer,type,size)
  131. register FILE *stream;
  132. char *buffer;
  133. int type;
  134. int size;
  135. {
  136.     if (stream->_buff)
  137.         return;
  138.     if (buffer && type != _IONBF) {
  139.         stream->_buff = buffer;
  140.         stream->_buflen = size;
  141.     } else {
  142.         stream->_buff = &stream->_bytbuf;
  143.         stream->_buflen = 1;
  144.     }
  145. }
  146. #endif
  147.  
  148.  
  149.  
  150.  
  151. #if    defined(MICROSOFT) || defined(AZTEC)
  152. setsignals()
  153. {
  154.     signal(SIGINT,SIG_IGN);
  155. }
  156. #endif
  157.  
  158. #if    defined(__TURBOC__)
  159. /* dummy do nothing */
  160. int catchit() {}
  161.  
  162. setsignals()
  163. {
  164.     ctrlbrk(catchit);
  165. }
  166.  
  167.  
  168. setvideo(s)
  169. char *s;
  170. {
  171.     if (strncmp("bios",s,4) == 0)
  172.         directvideo = 0;
  173.     else
  174.         directvideo = 1;
  175. }
  176. #endif
  177.  
  178. #if    defined(__TURBOC__)
  179. /* I use my own gets to get around the desqview raw mode bug
  180.    which causes gets not to work right.
  181.    I am doing it only for turbo C right now since its a pain to
  182.    get it right for them all.
  183.    it reads straight from console not via stdin.
  184. */
  185. char *
  186. gets(s)
  187. char *s;
  188. {
  189.     register char *p;
  190.     register int c;
  191.     p = s;
  192.     while ((c = getrch()) != EOF){
  193.         if ( c == '\b' && p > s) {
  194.             p--;
  195.             putch(' ');
  196.             putch('\b');
  197.         }
  198.         else if ( c == '\n' || c == '\r') {
  199.             break;
  200.         } else
  201.             *p++ = c;
  202.     }
  203.     *p = '\0';
  204.     putch('\n');
  205.     return(s);
  206. }
  207. #endif
  208.